package com.ruoyi.web.shopping.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.web.shopping.entity.Discounts;
import com.ruoyi.web.shopping.entity.Prices;
import com.ruoyi.web.shopping.service.DiscountsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/discounts")
@Slf4j
@Api(tags = "折扣相关接口")
public class DiscountsController {
    @Autowired
    private DiscountsService discountsService;

    /**
     * 查询折扣
     *
     * @param id
     * @return
     */
    @GetMapping("/select/{id}")
    @ApiOperation("查询折扣")
    public R<Discounts> selectById(@PathVariable String id) {
        log.info("查询折扣id为{}", id);
        Discounts discounts = discountsService.selectById(id);
        return R.ok(discounts);
    }

    /**
     * 修改折扣
     *
     * @param discounts
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改折扣")
    public R<String> update(@RequestBody Discounts discounts) {
        log.info("修改折扣为：{}", discounts);
        discountsService.update(discounts);
        return R.ok("修改成功");
    }

    /**
     * 删除折扣
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除折扣")
    public R<String> deleteById(@PathVariable String id) {
        log.info("删除折扣id为：{}", id);
        discountsService.deleteById(id);
        return R.ok("删除成功");
    }

    /**
     * 新增折扣
     *
     * @param discounts
     * @return
     */
    @PostMapping(value = "/save")
    @ApiOperation("新增折扣")
    public R<String> save(@RequestBody Discounts discounts) {
        log.info("新增折扣：{}", discounts);
        discountsService.save(discounts);
        return R.ok("新增成功");
    }
}
